//
//  YDHomeRecommendedStockCell.m
//  PeiZiWangBei
//
//  Created by LK-IOS on 2017/11/8.
//  Copyright © 2017年 LK-IOS. All rights reserved.
//

#import "YDHomeRecommendedStockCell.h"
#import "YDHomeReModel.h"

@interface YDHomeRecommendedStockCell()

//分割线
@property (nonatomic , weak) UIView *lineView;
//股票名称
@property (nonatomic , weak) UILabel *stockName;
//股票代码
@property (nonatomic , weak) UILabel *stockCode;
//涨跌状态
@property (nonatomic , weak) UILabel *upDownStatus;
//点买按钮
@property (nonatomic , weak) SYNoHeightedButton *saleButton;

@end


@implementation YDHomeRecommendedStockCell


-(void)setModel:(YDHomeReModel *)model
{
    _model = model;
    self.stockName.text = model.name;
    self.stockCode.text = model.code;
    self.upDownStatus.text = model.persentUpDown;
    if (model.priceColor == Price_Up) {
        self.upDownStatus.textColor = [UIColor colorWithHexString:paleRed];
    }else if (model.priceColor == Price_Down){
        self.upDownStatus.textColor = [UIColor colorWithHexString:leafyGreen];
    }else{
        self.upDownStatus.textColor = [UIColor colorWithHexString:dark];
    }
}

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *homeRecommendedStockCell = @"YDHomeRecommendedStockCell";
    YDHomeRecommendedStockCell *cell = [tableView dequeueReusableCellWithIdentifier:homeRecommendedStockCell];
    if (cell == nil) {
        cell = [[YDHomeRecommendedStockCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:homeRecommendedStockCell];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.contentView.backgroundColor = [UIColor clearColor];
        self.backgroundColor = [UIColor clearColor];
        [self bgView];
        [self lineView];
        [self stockName];
        [self stockCode];
        [self upDownStatus];
        [self saleButton];
        
    }
    return self;
}

-(UIView *)bgView
{
    if (_bgView == nil) {
        _bgView = [UIView new];
        [self.contentView addSubview:_bgView];
        _bgView.backgroundColor = self.contentView.backgroundColor;
        [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.top.equalTo(self.contentView);
        }];
    }
    return _bgView;
    
    
}

/****股票名称*****/
-(UILabel *)stockName
{
    if (_stockName == nil) {
        UILabel *stockName = [[UILabel alloc] init];
        [self.contentView addSubview:stockName];
        stockName.textColor = [UIColor colorWithHexString:dark];
        stockName.font = [UIFont systemFontOfSize:font16ScreenWRate * LKScreenW];
        stockName.textAlignment = NSTextAlignmentLeft;
        stockName.text = @"上海物贸";
        [stockName mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(rate375(15));
            make.centerY.equalTo(self);
        }];
        _stockName = stockName;
    }
    return _stockName;
}
/****股票代码*****/
-(UILabel *)stockCode
{
    if (_stockCode == nil) {
        UILabel *stockCode = [[UILabel alloc] init];
        [self.contentView addSubview:stockCode];
        stockCode.textColor = [UIColor colorWithHexString:blueyGrey];
        stockCode.font = [UIFont systemFontOfSize:font12ScreenWRate * LKScreenW];
        stockCode.textAlignment = NSTextAlignmentLeft;
        stockCode.text = @"000001";
        [stockCode mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(rate375(80));
            make.centerY.equalTo(self);
        }];
        _stockCode = stockCode;
    }
    return _stockCode;
}
-(UILabel *)upDownStatus
{
    if (_upDownStatus == nil) {
        UILabel *upDownStatus = [[UILabel alloc] init];
        [self.contentView addSubview:upDownStatus];
        upDownStatus.textColor = [UIColor colorWithHexString:paleRed];
        upDownStatus.font = [UIFont systemFontOfSize:font18ScreenWRate * LKScreenW];
        upDownStatus.textAlignment = NSTextAlignmentCenter;
        upDownStatus.text = @"3.15%";
        [upDownStatus mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.left.equalTo(@(rate375(170)));
        }];

        _upDownStatus = upDownStatus;
    }
    return _upDownStatus;
}
/****点买按钮*****/
-(SYNoHeightedButton *)saleButton
{
    if (_saleButton == nil) {
        SYNoHeightedButton *saleButton = [SYNoHeightedButton buttonWithType:UIButtonTypeCustom];
        [self.contentView addSubview:saleButton];
        saleButton.backgroundColor = [UIColor colorWithHexString:Orange];
        [saleButton setTitle:@"发布策略" forState:UIControlStateNormal];
        [saleButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        saleButton.titleLabel.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        saleButton.titleLabel.textAlignment = NSTextAlignmentCenter;
        saleButton.titleLabel.adjustsFontSizeToFitWidth = YES;
        [saleButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.width.equalTo(@(rate375(74)));
            if (isPhoneX) {
                make.height.equalTo(@(rateX812(24)));
            }else{
                make.height.equalTo(@(rate750(24)));
            }
            make.right.equalTo(self).offset(-rate375(15));
        }];
        saleButton.layer.cornerRadius = 3.0;
        saleButton.layer.masksToBounds = YES;
        [saleButton addTarget:self action:@selector(saleButtonClick) forControlEvents:UIControlEventTouchDown];
        _saleButton = saleButton;
    }
    return _saleButton;
}
-(void)saleButtonClick
{
    if ([self.delegate respondsToSelector:@selector(homeRecommendedStockCellSaleButtonClick:)]) {
        [self.delegate homeRecommendedStockCellSaleButtonClick:self];
    }
}

-(UIView *)lineView
{
    if (_lineView == nil) {
        UIView *lineView = [[UIView alloc] init];
        [self.contentView addSubview:lineView];
        lineView.backgroundColor = NumberColor(247, 247, 247);
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self);
            make.height.equalTo(@1);
        }];
        _lineView = lineView;
    }
    return _lineView;
}

@end
